﻿using BCCommon;
using BCDto.TMS.MarketingCoupon.MarketingCoupon;
using BCDto.TMS.MoveHouseConfig.MoveHouseServiceConfig;
using BCDto.TMS.MoveHouseConfig.MoveHouseServiceConfig.MoveHouseServiceConfigRequest;
using BCService.TMS.MoveHouseConfig.MoveHouseConfig;
using BCService.TMS.MoveHouseConfig.MoveHouseServiceConfig;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.MoveHouseConfig
{
    /// <summary>
    /// 搬家服务
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class MoveHouseServiceConfigController : ManagementBaseController
    {
        private readonly IMoveHouseServiceConfigService moveHouseServiceConfigService;
        public MoveHouseServiceConfigController(IMoveHouseServiceConfigService moveHouseServiceConfigService)
        {
            this.moveHouseServiceConfigService = moveHouseServiceConfigService;
        }

        /// <summary>
        /// 创建搬家服务。
        /// </summary>
        /// <param name="requestDto">搬家服务</param>
        /// <response code="201">创建搬家服务。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建搬家服务")]
        [ProducesResponseType(typeof(MoveHouseServiceConfigDto), 200)]
        public IActionResult Create(
            [FromBody] MoveHouseServiceConfigRequestDto requestDto)
        {
            var result = this.moveHouseServiceConfigService.Create(requestDto, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改搬家服务
        /// </summary>
        /// <param name="moveHouseServiceConfigId">搬家服务id</param>
        /// <param name="requestDto">搬家服务</param>
        /// <returns></returns>
        [HttpPut("[action]/{move_house_service_config_id}")]
        [ProducesResponseType(typeof(MoveHouseServiceConfigDto), 200)]
        public IActionResult GetSingle([FromRoute(Name = "move_house_service_config_id")] long moveHouseServiceConfigId,
            [FromBody] MoveHouseServiceConfigRequestDto requestDto)
        {
            var result = this.moveHouseServiceConfigService.Update(moveHouseServiceConfigId, requestDto, this.Admin);
            return this.Ok(result);
        }
        /// <summary>
        /// 修改搬家服务是否可用
        /// </summary>
        /// <param name="moveHouseServiceConfigId">搬家服务id</param>
        /// <param name="enabled">是否可用</param>
        /// <returns></returns>
        [HttpPut("[action]/{move_house_service_config_id}/{enabled}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "move_house_service_config_id")] long moveHouseServiceConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
                this.moveHouseServiceConfigService.Enabled(moveHouseServiceConfigId, this.Admin);
            else
                this.moveHouseServiceConfigService.Disabled(moveHouseServiceConfigId, this.Admin);
            return NoContent();
        }
        /// <summary>
        /// 删除搬家服务
        /// </summary>
        /// <param name="moveHouseServiceConfigId">搬家服务id</param>
        /// <returns></returns>
        [HttpDelete("{move_house_service_config_id}")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult Delete([FromRoute(Name = "move_house_service_config_id")] long moveHouseServiceConfigId)
        {
            var result = this.moveHouseServiceConfigService.Delete(moveHouseServiceConfigId);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取搬家服务
        /// </summary>
        /// <param name="isEnable">是否可用</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseServiceConfigDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "is_enable")] bool? isEnable)
        {
            var result = this.moveHouseServiceConfigService.GetList(isEnable);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取搬家服务
        /// </summary>
        /// <param name="isEnable">是否可用</param>
        /// <param name="serviceName">服务名称</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<MoveHouseServiceConfigDto>), 200)]
        public IActionResult Query([FromQuery(Name = "is_enable")] bool? isEnable,
            [FromQuery(Name = "service_name")] string serviceName,
            [FromQuery(Name = "create_start_date")] DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")] DateTime? createEndDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.moveHouseServiceConfigService.Query(isEnable, serviceName, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }

    }
}
